﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcHeatloss.Models
{
    public class CalcHeatoss
    {
        public static double CovertToMeters(double d)
        {
            const double convertFactor = 0.3;
            return d * convertFactor;
        }
        
        public static double CalcArea(double x, double y)
        {
            return x * y;
        }

        public static double CalcVolume(double x, double y, double z)
        {
            return x * y * z;
        }
        
        
        public static double AirHeatloss(double volume, double airMov, int temp)
        {
            const double ventilationUValue = 0.33;
            return volume * airMov * temp * ventilationUValue;
        }

        public static double FabricHeatloss(double uVal, double area, int temp)
        {
            return uVal * area * temp;
        }
        
        public static int TotalHeatCalc(Room room)
        {
            double temp = 0;
            foreach(Wall w in room)
            {
                temp += w.WallHeatloss;
            }
            temp += room.RoomCeiling.CeilingHeatloss + room.RoomFloor.FloorHeatloss + room.RoomAirHeatloss + 
                room.RoomDoors.DoorHeatloss + room.RoomWindows.WindowHeatloss + room.RoomSkylights.SkylightHeatloss;
            return (int)temp;
        }

        //public static double QuickCalc(Room room)
        //{
        //    ProjectEntities db = new ProjectEntities();

        //    // Default: internal ceiling, external floor, standard single glazed windows, 4 walls (2 external insulated)
        //    string defaultCeilingType = "Internal Ceiling";
        //    string defaultFloorType = "Un-insulated Floor";
        //    string defaultWindowType = "Single Glazed Window";
        //    string defaultExtWallType = "50mm cavity Wall (Insulated)";
        //    string defaultIntWallType = "Internal Wall";
        //    double windowPercentage = 0.4;
        //    double windowStdHeight = 1.2;
        //    int defaulNoOfWalls = room.NoOfWalls;

        //    // no outside doors or skylights
        //    room.RoomDoors.DoorHeatloss = 0.0;
        //    room.RoomSkylights.SkylightHeatloss = 0.0;
        //    // construct a default ceiling
        //    room.RoomCeiling.CeilingHeatloss = CalcHeatoss.FabricHeatloss((double)db.UValues.Where(d => d.Description == String.Format("{0}",defaultCeilingType))
        //        .Select(u => u.UValue1).First(),(double)(room.Width * room.Length), room.TemperatureDifference);
        //    //construct a defaul floor
        //    room.RoomFloor.FloorHeatloss = CalcHeatoss.FabricHeatloss((double)db.UValues.Where(d => d.Description == String.Format("{0}", defaultFloorType))
        //        .Select(u => u.UValue1).First(), (double)(room.Width * room.Length), room.TemperatureDifference);
        //    // construct a default window
        //    room.RoomWindows = new Window(windowStdHeight, ((double)room.Length * windowPercentage), String.Format("{0}",defaultWindowType),
        //        String.Format("{0}", room.TemperatureDifference) );
        //    // construct default walls
        //    room.RoomWalls = new Wall[defaulNoOfWalls];
        //    for (int i = 0; i < defaulNoOfWalls; i++)
        //    {
        //        if(i < (defaulNoOfWalls - 2))
        //        {
        //            room.RoomWalls[i] = new Wall((double)room.Height, (double)room.Length, String.Format("{0}",
        //                defaultIntWallType), String.Format("{0}", room.TemperatureDifference));
        //        }
        //        else
        //        {
        //            room.RoomWalls[i] = new Wall((double)room.Height, (double)room.Width, String.Format("{0}",
        //                defaultExtWallType), String.Format("{0}", room.TemperatureDifference));
        //        }
        //    }
        //    double answer = CalcHeatoss.TotalHeatCalc(room);
        //    return (int)answer;

        //}
       
    }
}